package com.naldo.goodcard.SQL;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DbHelper extends SQLiteOpenHelper {
	
    private static final String DATABASE_NAME = "cartoes.db";
    public static final String TABLE_NAME = "cartoes";

    private static final int DATABASE_VERSION = 1;
	public static final String ID = "_id";
	public static final String TIPO = "tipo";
	public static final String NUMERO = "numero";
	public static final String CPF = "cpf";
        
	private static final String DATABASE_CREATE = "create table "
	+ TABLE_NAME + "( " + ID
	+ " integer primary key autoincrement, " + TIPO
	+ " text not null, " + NUMERO + " text not null, "
	+ CPF + " text not null);";
	
	public DbHelper(Context context) {
         super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		 Log.w(DbHelper.class.getName(),
                 "Upgrading database from version " + oldVersion + " to "
                 + newVersion + ", which will destroy all old data");
                db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
                onCreate(db);
	}
}
